<?php 
class BrandController extends CommonController{
	private $model;
	public function __init(){
		parent::__init();
		$this->model=K("Brand");
	}
	public function index(){
	    $data=$this->model->order('sort asc')->all();
		$this->assign("data",$data);
		$this->display();
	}
	
	/**
	 * 添加
	 */
	public function add(){
		if(IS_POST){
			if(!$this->model->addbrand()) $this->error($this->model->error);
			$this->success("添加成功");
			
		}
		$this->display();
	}
	/**
	 * 上传
	 */
	public function upload(){
		$upload=new Upload('Upload/brand'.date('y/m'));
		$file=$upload->upload();
		if(empty($file)){
			$this->ajax('上传失败');
		}else{
			$data=$file[0];
			$this->ajax($data);
		}
		
	}
	/**
	 * 修改
	 */
	public function edit(){
		if(IS_POST){
			if(!$this->model->editbrand()) $this->error($this->model->error);
			$this->success('修改成功');
		}
		//获得旧数据
		$bid=Q("get.bid");
		$oldData=$this->model->where("bid={$bid}")->find();
		$this->assign('oldData',$oldData);
		$this->display();
		
	}
	/**
	 * 删除
	 */
	public function del(){
		$bid=Q("get.bid");
		$this->model->where("bid={$bid}")->delete();
		$this->success("删除成功");
	}
	/**
	 * 排序
	 */
	public function sortbrand(){
		if(IS_POST){
			if(!$this->model->brandsort()) $this->error($this->model->error);
			$this->success('修改成功');
		}
	}
}


 ?>